package com.aiyige.page.my.wallet.adapter;

import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.page.my.wallet.model.WalletSingleEntity;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WalletSingleDetailsListAdapter extends BaseQuickAdapter<WalletSingleEntity, BaseViewHolder> {

    @Override
    protected void convert(BaseViewHolder helper, WalletSingleEntity item) {
        ((MyHolder) helper).bindData(item);
    }

    public WalletSingleDetailsListAdapter() {
        super(new LinkedList<WalletSingleEntity>());
    }

    @Override
    protected int getDefItemViewType(int position) {
        return mData.get(position).getType();
    }


    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {

        BaseViewHolder baseViewHolder = new MyHolder(getItemView(getLayout(viewType), parent));
        return baseViewHolder;
    }


    private int getLayout(int viewType) {
        int layout = R.layout.item_wallet_single_keyvalue;
        switch (viewType) {
            case WalletSingleEntity.TYPE_KEY_VALUE:
                layout = R.layout.item_wallet_single_keyvalue;
                break;
            case WalletSingleEntity.TYPE_DETAIL:
                layout = R.layout.item_wallet_single_has_detail;
                break;
            case WalletSingleEntity.TYPE_INCOME:
                layout = R.layout.item_wallet_single_keyvalue_price_tag;
                break;
            case WalletSingleEntity.TYPE_ORDER_ID:
                layout = R.layout.item_wallet_single_order;
                break;
            case WalletSingleEntity.TYPE_GREY_VALUE:
                layout = R.layout.item_wallet_gray_value;
                break;

        }
        return layout;
    }

    public class MyHolder extends BaseViewHolder {
        @BindView(R.id.tv_key)
        TextView tvTitle;
        @BindView(R.id.tv_value)
        TextView tvValue;

        TextView tvDetail;

        WalletSingleEntity entity;

        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void bindData(final WalletSingleEntity baseEntity) {
            entity = baseEntity;
            tvTitle.setText(entity.getTitle());
            tvValue.setText(entity.getValue());
            if (entity.getType() == WalletSingleEntity.TYPE_ORDER_ID) {
                tvValue.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
                tvValue.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ARouter.getInstance()
                                .build(ARouterConfig.OrderDetailPage)
                                .withBoolean("isBuyer", entity.isBuyer())
                                .withBoolean("isOrderCodeRequest",true)
                                .withString("orderId", entity.getValue())
                                .navigation();

                    }
                });
            } else if (entity.getType() == WalletSingleEntity.TYPE_DETAIL) {

                tvDetail = itemView.findViewById(R.id.tv_detail);
                tvDetail.setText(entity.getDetail());
            }

//            if (entity.getType() != null && entity.getType().equals("outlay")) {
//                tvPrice.setText("-" + StringUtils.priceFormat(entity.getAmount()));
//            } else {
//                tvPrice.setText("+" + StringUtils.priceFormat(entity.getAmount()));
//            }
//            tvTitle.setText(entity.getDescribe());
//            tvWalletBalance.setText(mContext.getString(R.string.wallet_balance) + StringUtils.priceFormat(entity.getBalance()));
//            tvTime.setText(TimeUtils.dateToYYYYMMDDHHMM(entity.getCreateTime()));
//            tvPrice.setTextColor(ContextCompat.getColor(mContext, entity.isIncome() ? R.color.zwcolor_pink_f93684 : R.color.zwcolor_black_111111));
        }

    }

}
